package core;

public class Railway implements Item {
	private int price;
	private String name;
	private Player owner;
	private int group;
	private int nrItems;

	private int[] rentalPrice = new int[4];

	public Railway(String n, int p, int g, int nr, int r0, int r1, int r2,
			int r3) {
		name = new String(n);
		price = p;
		group = g;
		owner = null;
		nrItems = nr;

		rentalPrice[0] = r0;
		rentalPrice[1] = r1;
		rentalPrice[2] = r2;
		rentalPrice[3] = r3;
	}

	public Player getOwner() {
		return owner;
	}

	public boolean sell(Player p) {
		if (owner == null) {
			owner = p;
			return true;
		} else
			return false;
	}

	public String getName() {
		return name;
	}

	public boolean hasPrice() {
		return true;
	}

	public int getPrice() {
		return price;
	}

	public int getGroup() {
		return group;
	}

	public int getNrOfItemsInGroup() {
		return nrItems;
	}

	public int getRentalPrice(int thrownValue, int nr) {
		return rentalPrice[owner
				.getNrOfItemsOwnedFromGroup(this.getGroup() - 1)];
	}

	public boolean action(Player p) {
		return p.pay(this.getRentalPrice(p.getThrownValue(),
				owner.getNrOfItemsOwnedFromGroup(this.getGroup())));
	}

	public boolean hasGroup() {
		return true;
	}

}
